package boss.portal.common;

public class CommonController {
    /**
     * return success message
     *
     * @param data return data
     * @param <T>
     * @return
     */
    public <T> ResponseData success(T data) {
       ResponseData<T> response = new ResponseData<>();
        response.setCode(ResponseData.SUCCESS_CODE);
        response.setMsg(ResponseData.SUCCESS_MSG_DEFAULT);
        response.setData(data);
        response.setSuccess(true);
        return response;
    }

    /**
     * return success message
     *
     * @param msg return message
     * @param data return data
     * @param <T>
     * @return
     */
    public <T> ResponseData success(String msg, T data) {
        ResponseData<T> response = new ResponseData<>();
        response.setCode(ResponseData.SUCCESS_CODE);
        response.setMsg(msg);
        response.setData(data);
        response.setSuccess(true);
        return response;
    }

    /**
     * return success message
     *
     * @param msg return message
     * @return
     */
    public ResponseData success(String msg) {
        ResponseData response = new ResponseData();
        response.setCode(ResponseData.SUCCESS_CODE);
        response.setMsg(msg);
        response.setSuccess(true);
        return response;
    }

    /**
     * return error message
     *
     * @param msg return message
     * @return
     */
    public ResponseData error(String msg) {
        ResponseData response = new ResponseData();
        response.setCode(ResponseData.SUCCESS_CODE);
        response.setMsg(msg);
        response.setSuccess(false);
        return response;
    }

    /**
     * return error message
     *
     * @return
     */
    public ResponseData error() {
        ResponseData response = new ResponseData();
        response.setCode(ResponseData.ERROR_CODE);
        response.setMsg(ResponseData.ERROR_MSG_DEFAULT);
        response.setSuccess(false);
        return response;
    }
}
